package ch.sv7.tool.dbmanager.db.fix;

import ch.sv7.tool.dbmanager.db.IndexSchema;
import ch.sv7.tool.dbmanager.db.SchemaElement;
import ch.sv7.tool.dbmanager.db.dialect.DialectException;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class DropIndexFix extends AbstractSchemaFix implements SchemaFix {

	private IndexSchema indexSchema;

	/**
	 * @param missingIndexDifference
	 */
	public DropIndexFix(IndexSchema indexSchema) {
		super();
		this.indexSchema = indexSchema;
	}

	public SchemaElement getActionTarget() {
		return indexSchema;
	}
	
	public String getSQLFix() throws DialectException {
		String ddl = "\n-- Drop Index Fix \n";
		ddl += getDialect().getDropIndexDDL(indexSchema);
		return ddl;
	}

	public int getPriority() {
		if (indexSchema.isPrimaryKey()){
			return SchemaFix.PRIORITY_PK_INDEX_DROP;
		} else if (indexSchema.isUnique()) {
			return SchemaFix.PRIORITY_UNIQUE_INDEX_DROP;
		} else {
			return SchemaFix.PRIORITY_INDEX_DROP;
		}
	}

	public String getDescription() {
		return "Drop index " + indexSchema.getTableSchema().getName()+"."+indexSchema.getName();
	}

	public int getAction() {
		return ACTION_DROP;
	}

}
